/****************************************************
          File Name:9-4_imply.cpp
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sun 21 Dec 2014 03:22:19 PM CST
*****************************************************/

#include"9-4.h"
#include<iostream>

namespace SALES
{
    void setSale(Sales & s, const double ar[], int n)
    {
        double ave = 0;
        double max = ar[0];
        double min = ar[0];
        for(int i=0; i<n && i <QUARTERS; i++)
        {
            s.sales[i] = ar[i];
            ave += ar[i];
            if(max < ar[i])
                max = ar[i];
            if(min > ar[i])
                min = ar[i];
        }

        s.max = max;
        s.min = min;
        s.average = ave;
    }

    void setSale(Sales & s)
    {
        for(int i=0; i<QUARTERS; i++)
        {
            std::cout << "Enter sales: ";
            std::cin >> s.sales[i];
        }

        double ave = 0;
        double max = s.sales[0];
        double min = s.sales[0];

        for(int i=0; i<QUARTERS; i++)
        {
            ave += s.sales[i];
            if(max < s.sales[i])
                max = s.sales[i];
            if(min > s.sales[i])
                min = s.sales[i];
        }

        s.max = max;
        s.min = min;
        s.average = ave;
    }

    void showSale(const Sales & s)
    {
        std::cout << "sales: ";
        for(int i = 0; i<QUARTERS; i++)
            std::cout << s.sales[i] <<" ";
        std::cout << std::endl;
        std::cout << "average: " << s.average << std::endl;
        std::cout << "max: " << s.max << std::endl;
        std::cout << "min: " << s.min << std::endl; 
    }
}
